import processing.serial.*;


Serial myPort;

int COLS = 20;
int ROWS = 2;
int[][] line = new int[10][640];


PImage img;

void setup(){




  myPort = new Serial(this, Serial.list()[0], 19200);
  println(Serial.list());
  img = loadImage("renstimpy2.png");


  for(int l = 0; l < 10; l++){

    int arrayIndex = 0;

    int length = COLS * ROWS * 16;

    print("byte line["+length+"] = {");
    for(int r = 0; r<ROWS; r++){
      for(int c = 0; c<COLS; c++){

        for(int ir=0; ir<8; ir++){
          int bp1 = 0;
          int bp2 = 0;


          for(int ic=0; ic<8; ic++){
            color p = img.get(c*8+ic, r*8+ir+l*16);
            if(red(p) > 128) {
              bp1 += 1 << (7-ic);
            }
            bp2 = bp1;
          } 





          line[l][arrayIndex ] = (int)bp1;

          arrayIndex++;
          line[l][arrayIndex ] = (int)bp2;
          arrayIndex++;

          print(bp1+","+bp2+",");
        }
      } 
    }

  }

  println("}");
}


void draw(){

}

void keyPressed(){



  
  println("send");

 for(int l = 0; l < 10; l++){
  for(int i = 0; i< 640; i++){
    print(line[l][i]+",");
    myPort.write(line[l][i]); 

  } 
      delay(2000);
}
}

